package com.ciwong.epaper.modules.reciteWords.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.reciteWords.bean.JiaoCaiBean;

import java.util.List;

/**
 * Created by keepon on 2018/9/13.
 */
public class JiaoCaiDetailAdapter extends BaseRecyclerViewAdapter<JiaoCaiBean,JiaoCaiDetailAdapter.JiaoCaiNameViewHolder>  {
	private  int mCurrentSelectedPos  =-1;

	public JiaoCaiDetailAdapter(Context context, List<JiaoCaiBean> datas) {
		super(context, datas);
	}

	@Override
	public JiaoCaiNameViewHolder onCreateMyViewHolder(@NonNull ViewGroup parent, int viewType) {
		View inflate = LayoutInflater.from(mContext).inflate(R.layout.layout_tv_jiaocai, parent, false);
		return new JiaoCaiNameViewHolder(inflate);
	}

	@Override
	public void onBindMyViewHolder(@NonNull JiaoCaiNameViewHolder holder, int position) {
		holder.bindData(position,mDatas.get(position));
	}


	public class JiaoCaiNameViewHolder extends RecyclerView.ViewHolder {
		TextView mTvJiaoCaiName;
		public JiaoCaiNameViewHolder(View itemView) {
			super(itemView);
			mTvJiaoCaiName = itemView.findViewById(R.id.tv_jiaocai_name);
		}

		public void bindData(final int position, final JiaoCaiBean jiaoCaiBean) {
			mTvJiaoCaiName.setText(jiaoCaiBean.getVersionName());
			if(jiaoCaiBean.isSelected()){
				mTvJiaoCaiName.setSelected(true);
				mCurrentSelectedPos=position;
			}else{
				mTvJiaoCaiName.setSelected(false);
			}
			itemView.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					if(mOnItemClickListener!=null){
						mTvJiaoCaiName.setSelected(true);
						mOnItemClickListener.onItemClick(position,jiaoCaiBean);
					}
				}
			});
		}
	}




}
